//
//  WHCompanyInfoApplyModel.m
//  WHEasyBizLink
//
//  Created by shengmeng chen on 2024/11/23.
//


#define kTitleArr @[kComName,kComType,kComCode,kBanknm,kBankSubnm,kaccountnm,kaccountno,kComRegion,kComAddr,kComPerson,kComTel,kIsManger]


#import "WHCompanyInfoApplyModel.h"
#import "WHWproxyKitUtility.h"
#import "NSObject+MJKeyValue.h"
#import "WHTdsModel.h"
#import "CommonTools.h"
#import "WHEnterpriseCompanyModel.h"
#import <WHWlproxy/WHKeyChainDataManager.h>
#import <WHTree/WHTree.h>


@implementation WHCompanyInfoApplyModel

+ (void)fetchDatasSuccessBlock:(void (^)(id models))succese
{
    
//    NSArray *titleNames = @[@"单位名称",@"单位类型",@"机构代码",@"所属区域",@"开户银行名称",@"银行账户名称",@"银行账号",@"单位地址",@"单位电话",@"是否物联管理单位",@"单位序号"];
    
    NSArray *titleNames = kTitleArr;
    
     NSArray *holderNames = @[@"例如:北京ABC科技有限公司",@"例如:单位类型",@"例如:91110108MA01A12345",@"例如:中国农业银行",@"例如:海淀区支行",@"例如:北京ABC科技有限公司",@"例如:9111010800001A12345",@"北京市海淀区 ",@"例如:北京市海淀区xxx路xxx号",@"例如:张三",@"例如:13700000011",@""];
    
    NSMutableArray*models =[NSMutableArray new];
    
    for (int i =0 ; i<titleNames.count; i++) {
        
        WHCompanyInfoApplyModel *model =[WHCompanyInfoApplyModel new];
        model.titleName  = titleNames[i];
        model.holderName = holderNames[i];
        model.isMust     = YES;
        if ([model.titleName isEqualToString:kComAddr]||[model.titleName isEqualToString:kComPerson]||[model.titleName isEqualToString:kComTel]) {
            model.isMust = NO;
        }
        if ( [model.titleName isEqualToString:kIsManger]) {
            model.isSelect = YES;
        }
        [models addObject:model];
    }
    NSArray *result =models;
    succese(result);
}

+ (void)fetchDatasWithModel:(WHEnterpriseCompanyModel*)companyModel SuccessBlock:(void (^)(id models))succese
{
    
//    NSArray *titleNames = @[@"单位名称",@"单位类型",@"机构代码",@"所属区域",@"开户银行名称",@"银行账户名称",@"银行账号",@"单位地址",@"单位电话",@"是否物联管理单位",@"单位序号"];
    
    NSArray *titleNames = kTitleArr;
    NSMutableArray*models =[NSMutableArray new];
    for (int i =0 ; i<titleNames.count; i++) {
        
        WHCompanyInfoApplyModel *model =[WHCompanyInfoApplyModel new];
        model.titleName  = titleNames[i];
        if ([model.titleName isEqualToString:kComName]) {
            model.contents =companyModel.comname;
            model.code     =companyModel.comid;
        }else if ([model.titleName isEqualToString:kComType])
        {
            model.contents =companyModel.comtypenm;
            model.code     =companyModel.comtype;
            
        }else if ([model.titleName isEqualToString:kComCode])
        {
            model.contents  = companyModel.comcode;
        }
        else if ([model.titleName isEqualToString:kBanknm])
        {
             model.contents =companyModel.banknm ;
             model.code     =companyModel.bankcode ;
        }else if ([model.titleName isEqualToString:kBankSubnm])
        {
             model.contents =companyModel.subbanknm ;
           
        }else if ([model.titleName isEqualToString: kaccountnm])
        {
            model.contents =companyModel.accountnm;
        }
        else if ([model.titleName isEqualToString:kaccountno])
        {
             model.contents = companyModel.accountno ;
        
        }else if ([model.titleName isEqualToString:kComRegion])
        {      model.contents =companyModel.regionnm;
               model.code     =companyModel.regionid;
        }else if ([model.titleName isEqualToString:kComAddr])
        {
             model.contents = companyModel.addr;
        }else if ([model.titleName isEqualToString:kComPerson])
        {
            model.contents = companyModel.linkuser ;
        }else if ([model.titleName isEqualToString:kComTel])
        {
            model.contents = companyModel.linktel;
            
        }else if ([model.titleName isEqualToString:kIsManger])
        {
              model.contents = companyModel.isctr;
        }
        
        model.isMust     = YES;
        if ([model.titleName isEqualToString:kComAddr]||[model.titleName isEqualToString:kComPerson]||[model.titleName isEqualToString:kComTel]) {
            model.isMust = NO;
        }
        if ( [model.titleName isEqualToString:kIsManger]) {
            model.isSelect = YES;
        }
        //只有企业才有机构代码
        if ([model.titleName isEqualToString:kComCode]){
            if ([companyModel.comtype isEqualToString:kComType99]) {
                [models addObject:model];
            }
        }else
        {
            [models addObject:model];
        }
        
    }
    NSArray *result =models;
    succese(result);
}


@end


@implementation WHInfoModel


+(WHInfoModel*)changeWHCompanyInfoApplyModels:(NSArray*)models
{
    WHInfoModel*m = [WHInfoModel new];
    for(int i=0;i<models.count;i++)
    {
        WHCompanyInfoApplyModel* model = models[i];
        
        if ([model.titleName isEqualToString:kComName]) {
            m.name  = model.contents;
        }else if ([model.titleName isEqualToString:kComType])
        {
            m.tradetype  = model.code;
        }else if ([model.titleName isEqualToString:kComCode])
        {
            m.code  = model.contents;
        }
        else if ([model.titleName isEqualToString:kBanknm])
        {
            m.banknm   = model.contents;
            m.bankcode = model.code;
        }else if ([model.titleName isEqualToString:kBankSubnm])
        {
            m.subbanknm = model.contents;
           
        }else if ([model.titleName isEqualToString: kaccountnm])
        {
            m.accountnm  = model.contents;
        }
        else if ([model.titleName isEqualToString:kaccountno])
        {
            m.accountno  = model.contents;
        
        }else if ([model.titleName isEqualToString:kComRegion])
        {
            m.region  = model.code;
        }else if ([model.titleName isEqualToString:kComAddr])
        {
            m.addr  = model.contents;
        }else if ([model.titleName isEqualToString:kComPerson])
        {
            m.linkuser  = model.contents;
        }else if ([model.titleName isEqualToString:kComTel])
        {
            m.tel  = model.contents;
        }else if ([model.titleName isEqualToString:kIsManger])
        {
            m.isctr = model.contents;
        }
    }
    return m;
}

+(void)checkItem:(WHInfoModel*)model succesefulBlock:(void (^)(NSString* str))succese andFailureBlock:(void (^)(NSString *error))failure{
    
    if (model.name.length==0) {
        failure(@"单位名称为空,请您填写");
    }else if (model.tradetype.length==0)
    {
        failure(@"单位类型为空,请您填写");
   
    }else if (model.code.length==0&&[model.tradetype isEqualToString:kComType99])
    {
        failure(@"机构代码为空,请您填写");
    }else if (model.region.length==0)
    {
        failure(@"所属区域为空,请您填写");
      
    }else if (model.banknm.length==0||model.bankcode.length==0)
    {
        failure(@"开户银行为空,请您填写");
    }else if (model.subbanknm.length==0)
    {
        failure(@"开户支行为空,请您填写");
    }
    else if (model.accountnm.length==0)
    {
        failure(@"户主名称为空,请您填写");
    }
    else if (model.accountno.length==0)
    {
        failure(@"银行账号为空,请您填写");
    }else
    {
        succese(@"填写完成");
    }
}

/*
 
 单位开户Pkg_Company.p_Company_Oper
 入参描述
     {
       "callMainTdsProc": "1",
       "callFromType": "0",
       "userid":"000000",
       "procId":"pkg_company.p_Company_oper",
       "opertype":"1:添加 0:删除 2:修改",
       "id":"TDS平台标识",
       "comid":"单位标识，增加时可为空，删除修改时必填",
       "name":"单位名称",
       "code":"机构代码",
       "tradetype":"单位类型",
       "region":"所属区域",
       "bankcode":"开户银行代码，传开户银行的编码，例如'102'",
       "subbanknm":"开户支行，必填",
       "accountnm":"银行账户名称",
       "accountno":"银行账号",
       "addr":"单位地址，可为空",
       "linkuser":"联系人",
       "tel":"单位电话，可为空",
       "isctr":"是否物联管理单位 1-是 0-不是",
       "sort":"单位序号，可为空",
       "phone": [
         {
           "udid":"注册手机唯一标识",
           "number":"注册手机号码",
           "brand":"手机品牌，可为空",
           "brandmodel":"品牌型号，可为空"
         }
       ],
                  
       "operuri" : "操作人标识",
       "operunm" : "操作人姓名"
     }
 出参描述：
   {
    "dataList": [
     {
     
       "id": "单位标识",
       "appid": "所属空间标识",
       "proxys": [
         {
           "id": "代理标识",
           "url": "代理地址"
         },
         {
           "id": "代理标识",
           "url": "代理地址"
         }
       ]
      
     }

 
 */

+(void)sendCompanyInfo:(WHInfoModel*)model withTSD:(NSDictionary*)dict withopertype:(WHComOPType)opertype withBlock:(void (^)(id responseObject))succese failureBlock:(void (^)(NSString *msg))failure{
    
    NSString *tdsId  = dict[@"TDSid"];
    NSString *target = dict[@"TDSid"];
    NSString *proxy  = dict[@"url"];
    
    NSString *json = [NSString stringWithFormat:@"\"callMainTdsProc\":\"%@\"",@"1"];
    json = [json stringByAppendingFormat:@",\"callFromType\":\"%@\"",@"0"];
    json = [json stringByAppendingFormat:@",\"userid\":\"%@\"",@"000000"];
    json = [json stringByAppendingFormat:@",\"procId\":\"pkg_company.p_Company_oper\""];
    json = [json stringByAppendingFormat:@",\"opertype\":\"%lu\"",(unsigned long)opertype];
    json = [json stringByAppendingFormat:@",\"id\":\"%@\"",tdsId];
    json = [json stringByAppendingFormat:@",\"comid\":\"%@\"",[CommonTools checkStringIsNull:model.comid]];
    json = [json stringByAppendingFormat:@",\"name\":\"%@\"",model.name];
    json = [json stringByAppendingFormat:@",\"code\":\"%@\"",[CommonTools checkStringIsNull:model.code]];
    json = [json stringByAppendingFormat:@",\"tradetype\":\"%@\"",model.tradetype];
    json = [json stringByAppendingFormat:@",\"region\":\"%@\"",model.region];
    
    json = [json stringByAppendingFormat:@",\"bankcode\":\"%@\"",model.bankcode];
    json = [json stringByAppendingFormat:@",\"banknm\":\"%@\"",model.banknm];
    json = [json stringByAppendingFormat:@",\"subbanknm\":\"%@\"",model.subbanknm];
    
    json = [json stringByAppendingFormat:@",\"accountnm\":\"%@\"",model.accountnm];
    json = [json stringByAppendingFormat:@",\"accountno\":\"%@\"",model.accountno];
    json = [json stringByAppendingFormat:@",\"addr\":\"%@\"",[CommonTools checkStringIsNull:model.addr]];
    json = [json stringByAppendingFormat:@",\"tel\":\"%@\"",[CommonTools checkStringIsNull:model.tel]];
    json = [json stringByAppendingFormat:@",\"linkuser\":\"%@\"",[CommonTools checkStringIsNull:model.linkuser]];
    json = [json stringByAppendingFormat:@",\"isctr\":\"%@\"",model.isctr];
    NSString *sort = [CommonTools checkStringIsNull:model.sort];
    
    sort           = [WHInfoModel isStringOnlyNumbers:sort]? sort:@"";
    json = [json stringByAppendingFormat:@",\"sort\":\"%@\"",sort];
    
    NSString*udid= [WHKeyChainDataManager readUUID]; //读取
    
    if (udid.length==0)
    {
        udid = [[UIDevice currentDevice].identifierForVendor UUIDString];
        [WHKeyChainDataManager saveUUID:udid];  //存入
    }
    NSString *phone =[NSString stringWithFormat:@"[{\"udid\":\"%@\",\"number\":\"%@\",\"brand\":\"%@\",\"brandmodel\":\"%@\"}]",udid,kApp.userPhone,@"iphone",@""];
    
    json = [json stringByAppendingFormat:@",\"phone\":%@",phone];
    
    json = [json stringByAppendingFormat:@",\"operuri\":\"%@\"",kApp.userQcode];
    json = [json stringByAppendingFormat:@",\"operunm\":\"%@\"",kApp.userName];
    
    NSString *soapStr = [NSString stringWithFormat:@"{%@}",json];

    WHWproxyKitUtility *whwProxyKit =
    [[WHWproxyKitUtility new] initWithProxyIP:proxy
                                    targetUri:target
                                    getParams:soapStr];

    whwProxyKit.mParamsHaveEncoded = YES;
    whwProxyKit.mUserType = @"0";
    [whwProxyKit getSyncActionWithprogress:^(NSString * _Nonnull result) {
    } success:^(NSString * _Nonnull result,NSString * _Nonnull xml, NSString * _Nonnull path){
        NSData *jsonData = [xml dataUsingEncoding:NSUTF8StringEncoding];
        NSError *err;
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
        NSString*code = dict[REQUEST_RESP_CODE];
        NSString*msg  = dict[REQUEST_RESP_MSG];
        if ([code isEqualToString:REQUEST_RESP_EC00]){
            NSArray *list = dict[@"dataList"];
            if (list.count>0) {
             
            }
//            NSArray *models = [WHTradeTypeModel objectArrayWithKeyValuesArray:list];
            succese(list);
        }else{
            failure(msg);
        }
    } failure:^(NSString * _Nonnull result) {
        failure(result);
    }];
}
//操作公司
//comid 公司id
//dict TDSid:平台标识 url 代理地址
//opertype 0:删除 2:修改 4:启用/停用
//succese 成功
//failure 失败
+(void)setCompanyInfo:(NSString*)comid withTSD:(NSDictionary*)dict withopertype:(WHComOPType)opertype withBlock:(void (^)(id responseObject))succese failureBlock:(void (^)(NSString *msg))failure{
    
    NSString *tdsId  = dict[@"TDSid"];
    NSString *target = dict[@"TDSid"];
    NSString *proxy  = dict[@"url"];
    
    NSString *json = [NSString stringWithFormat:@"\"callMainTdsProc\":\"%@\"",@"1"];
    json = [json stringByAppendingFormat:@",\"callFromType\":\"%@\"",@"0"];
    json = [json stringByAppendingFormat:@",\"userid\":\"%@\"",@"000000"];
    json = [json stringByAppendingFormat:@",\"procId\":\"pkg_company.p_Company_oper\""];
    json = [json stringByAppendingFormat:@",\"opertype\":\"%lu\"",(unsigned long)opertype];
    json = [json stringByAppendingFormat:@",\"id\":\"%@\"",tdsId];
    json = [json stringByAppendingFormat:@",\"comid\":\"%@\"",comid];
   
    json = [json stringByAppendingFormat:@",\"operuri\":\"%@\"",kApp.userQcode];
    json = [json stringByAppendingFormat:@",\"operunm\":\"%@\"",kApp.userName];
    
    NSString *soapStr = [NSString stringWithFormat:@"{%@}",json];

    WHWproxyKitUtility *whwProxyKit =
    [[WHWproxyKitUtility new] initWithProxyIP:proxy
                                    targetUri:target
                                    getParams:soapStr];

    whwProxyKit.mParamsHaveEncoded = YES;
    whwProxyKit.mUserType = @"0";
    [whwProxyKit getSyncActionWithprogress:^(NSString * _Nonnull result) {
    } success:^(NSString * _Nonnull result,NSString * _Nonnull xml, NSString * _Nonnull path){
        NSData *jsonData = [xml dataUsingEncoding:NSUTF8StringEncoding];
        NSError *err;
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
        NSString*code = dict[REQUEST_RESP_CODE];
        NSString*msg  = dict[REQUEST_RESP_MSG];
        if ([code isEqualToString:REQUEST_RESP_EC00]){
            NSArray *list = dict[@"dataList"];
            if (list.count>0) {
             
            }
//            NSArray *models = [WHTradeTypeModel objectArrayWithKeyValuesArray:list];
            succese(list);
        }else{
            failure(msg);
        }
    } failure:^(NSString * _Nonnull result) {
        failure(result);
    }];
}

//
+(BOOL)isStringOnlyNumbers:(NSString *)string {
    
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    NSNumber *number = [formatter numberFromString:string];

    if (number != nil) {
        NSLog(@"The string is a number.");
        return  YES;
    } else {
        NSLog(@"The string is not a number.");
        return NO;
    }

}


@end

@implementation WHTradeTypeModel


/**4、查询系统代码信息
 入参描述：
 {
     "callMainTdsProc": "1",
     "callFromType": "0",
     "userid":"000000",
     "procId":"Pkg_Pbl_Def.p_Getsyscodeinfo",
     "pcode":"上级代码",
     "operuri" : "操作人标识",
     "operunm" : "操作人姓名"
 }
 
 出参描述
 {
   "dataListAllCount": 2,
   "dataList": [
     {
        "rn": "1",
        "code": "代码",
        "name": "名称"
     },
     {
        "rn": "2",
        "code": "代码",
        "name": "名称"
     }
   ],
   "code": "EC00",
   "msg": "处理成功"
 }
*/
+(void)getTDSSystemWithBlock:(void (^)(id responseObject))succese FailureBlock:(void (^)(NSString *msg))failure{
    
    NSString *json = [NSString stringWithFormat:@"\"callMainTdsProc\":\"%@\"",@"1"];
    json = [json stringByAppendingFormat:@",\"callFromType\":\"%@\"",@"0"];
    json = [json stringByAppendingFormat:@",\"userid\":\"%@\"",@"000000"];
    json = [json stringByAppendingFormat:@",\"pcode\":\"%@\"",@"ComType"];
    json = [json stringByAppendingFormat:@",\"operuri\":\"%@\"",kApp.userQcode];
    json = [json stringByAppendingFormat:@",\"operunm\":\"%@\"",kApp.userName];
    json = [json stringByAppendingFormat:@",\"procId\":\"Pkg_Pbl_Def.p_Getsyscodeinfo\""];
    NSString *soapStr = [NSString stringWithFormat:@"{%@}",json];
    
    NSArray *arr = @[debugAddress,debugAddress2];
    NSUInteger randomIndex = arc4random_uniform((u_int32_t)arr.count);
    NSString * proxy  = arr[randomIndex];
    NSString * target = debugAppId;
    
    WHWproxyKitUtility *whwProxyKit =
    [[WHWproxyKitUtility new] initWithProxyIP:proxy
                                    targetUri:target
                                    getParams:soapStr];

    whwProxyKit.mParamsHaveEncoded = YES;
    whwProxyKit.mUserType = @"0";
    [whwProxyKit getSyncActionWithprogress:^(NSString * _Nonnull result) {
    } success:^(NSString * _Nonnull result,NSString * _Nonnull xml, NSString * _Nonnull path){
        NSData *jsonData = [xml dataUsingEncoding:NSUTF8StringEncoding];
        NSError *err;
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
        NSString*code = dict[REQUEST_RESP_CODE];
        NSString*msg  = dict[REQUEST_RESP_MSG];
        if ([code isEqualToString:REQUEST_RESP_EC00]){
            NSArray *list = dict[@"dataList"];
            if (list.count>0) {
             
            }
            NSArray *models = [WHTradeTypeModel objectArrayWithKeyValuesArray:list];
            succese(models);
        }else{
            failure(msg);
        }
    } failure:^(NSString * _Nonnull result) {
        failure(result);
    }];
}

+(NSMutableArray*)getTitleUnitTypeInfo:(NSArray *)array
{
    NSMutableArray*marray = [NSMutableArray new];
    for(int i=0;i<array.count;i++)
    { WHTradeTypeModel*model =array[i];
        [marray addObject:model.name];
    }
    return marray;
}

@end

@implementation WHRegionalModel


/**3、查询所属区域信息
 {
     "callMainTdsProc": "1",
     "callFromType": "0",
     "userid":"000000"，
     "procId":"Pkg_Query_Service5.p_query_region",
     "pid":"上级区域，0-为一级区域"，
     "operuri" : "操作人标识",
     "operunm" : "操作人姓名"
   }
出参描述：

{
"dataListAllCount": 2,
"dataList": [
 {
    "rn": "1",
   "id": "区域标识",
   "name": "区域名称",
   "sort": "区域序号"
 },
 {
    "rn": "2",
   "id": "区域标识",
   "name": "区域名称",
   "sort": "区域序号"
 }
],
"code": "EC00",
"msg": "处理成功"
}
*/
+(void)getTDSRegionalWithPid:(NSString*)pid Block:(void (^)(id responseObject))succese FailureBlock:(void (^)(NSString *msg))failure{
    
    NSString *json = [NSString stringWithFormat:@"\"callMainTdsProc\":\"%@\"",@"1"];
    json = [json stringByAppendingFormat:@",\"callFromType\":\"%@\"",@"0"];
    json = [json stringByAppendingFormat:@",\"userid\":\"%@\"",@"000000"];
    json = [json stringByAppendingFormat:@",\"pid\":\"%@\"",pid];
    json = [json stringByAppendingFormat:@",\"operuri\":\"%@\"",kApp.userQcode];
    json = [json stringByAppendingFormat:@",\"operunm\":\"%@\"",kApp.userName];
    json = [json stringByAppendingFormat:@",\"procId\":\"Pkg_Query_Service5.p_query_region\""];
    NSString *soapStr = [NSString stringWithFormat:@"{%@}",json];
    
    NSArray *arr = @[debugAddress,debugAddress2];
    NSUInteger randomIndex = arc4random_uniform((u_int32_t)arr.count);
    NSString * proxy  = arr[randomIndex];
    NSString * target = debugAppId;
    
    WHWproxyKitUtility *whwProxyKit =
    [[WHWproxyKitUtility new] initWithProxyIP:proxy
                                    targetUri:target
                                    getParams:soapStr];

    whwProxyKit.mParamsHaveEncoded = YES;
    whwProxyKit.mUserType = @"0";
    [whwProxyKit getSyncActionWithprogress:^(NSString * _Nonnull result) {
    } success:^(NSString * _Nonnull result,NSString * _Nonnull xml, NSString * _Nonnull path){
        NSData *jsonData = [xml dataUsingEncoding:NSUTF8StringEncoding];
        NSError *err;
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
        NSString*code = dict[REQUEST_RESP_CODE];
        NSString*msg  = dict[REQUEST_RESP_MSG];
        if ([code isEqualToString:REQUEST_RESP_EC00]){
            NSArray *list = dict[@"dataList"];
            if (list.count>0) {
             
            }
//            NSArray *models = [WHRegionalModel objectArrayWithKeyValuesArray:list];
            succese(list);
        }else{
            failure(msg);
        }
    } failure:^(NSString * _Nonnull result) {
        failure(result);
    }];
}

#pragma mark -树结构
+(WHTreeManager *)getTreeDatasWtihArr:(NSArray*)arr
{
    NSMutableSet *items = [NSMutableSet set];

    // 第一级
    for (NSInteger i = 0; i < arr.count; i++)
    {
            NSDictionary*dic   = arr[i];
            NSString * title   = dic[@"name"];
            NSString * ID      = dic[@"id"];
            NSString * rn      = dic[@"rn"];
            WHTreeItem *level1 = [[WHTreeItem alloc] initWithName:title
                                                               ID:ID
                                                         parentID:@""
                                                          orderNo:rn
                                                             type:@""
                                                           isLeaf:NO
                                                             data:dic];
            [items addObject:level1];
            
        }
    WHTreeManager *manager = [[WHTreeManager alloc] initWithItems:items andExpandLevel:0];
    
    return manager;
}
#pragma mark 拼树子节点
+(WHTreeManager *)writeTreeChildWtihArr:(NSArray*)arr
                            treeManager:(WHTreeManager *)treeManager parentID:(NSString*)parentID
{
    NSMutableArray<WHTreeItem *> *allitems = treeManager.allItems;
    NSMutableSet *items = [NSMutableSet setWithArray:allitems];
    for (NSInteger i = 0; i < arr.count; i++)
    {
        NSDictionary *dic  = arr[i];
        NSString * title   = dic[@"name"];
        NSString * ID      = dic[@"id"];
        NSString * rn      = dic[@"rn"];
        WHTreeItem *level1 = [[WHTreeItem alloc] initWithName:title
                                                           ID:ID
                                                     parentID:parentID
                                                      orderNo:rn
                                                         type:@""
                                                       isLeaf:NO
                                                         data:dic];
        [items addObject:level1];
    }
    
    WHTreeManager *manager = [[WHTreeManager alloc] initWithItems:items andExpandLevel:0];
    return manager;
}

@end

@implementation WHBankModel

+(NSArray *)getWHBankModels
{
    NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"WHBank" ofType:@"plist"]];
    NSMutableArray *data = [[NSMutableArray alloc] initWithCapacity:array.count];
    for (NSDictionary *dic in array) {
        WHBankModel *m = [[WHBankModel alloc] init];
        m.bankID    =[dic objectForKey:@"bankID"];
        NSString *bankName =[dic objectForKey:@"bankName"];
        m.bankName  =[bankName stringByReplacingOccurrencesOfString:@"\n" withString:@""];
        [data addObject:m];
    }
    return data;
}

+(NSArray *)getWHBankTitle
{
    NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"WHBank" ofType:@"plist"]];
    NSMutableArray *data = [[NSMutableArray alloc] initWithCapacity:array.count];
    for (NSDictionary *dic in array) {
        WHBankModel *m = [[WHBankModel alloc] init];
        NSString *bankName =[dic objectForKey:@"bankName"];
        m.bankName  =[bankName stringByReplacingOccurrencesOfString:@"\n" withString:@""];
        [data addObject:m.bankName];
    }
    return data;
}


@end


